/*
*	del confirm
*	by Author
*	2014.1.10
*/

var url = null;
function del(id,model){//删除
	if(id==''||model==''){
		alert('非法操作!');
		return false;	
	}
	$('#SysDel').dialog('open');
	url = APP+"/do/del/id/"+id+"/model/"+model;
}
function dels(model){//删除多个
	var check =[];    
	$('input[name="tag"]:checked').each(function(){    
	    check.push($(this).val());
	});
	var id = check.join(',');
	if(id=='')alert('请选择需要删除的选项!');
	else if(model=='')alert('非法操作!');
	else{
		$('#SysDel').dialog('open');
		url = APP+"/do/dels/id/"+id+"/model/"+model;		
	}
}

function obs(cls,model,act,data){
	if(cls==''||model==''||data==''){
		alert('非法操作!');
		return false;	
	}
	$('#SysDone').dialog('open');
	url = APP+"/do/obs/cls/"+cls+"/model/"+model+"/act/"+act+"/"+data;
}

function move(model,obj){//转移
	var check =[];    
	$('input[name="tag"]:checked').each(function(){    
	    check.push($(this).val());
	});
	var id = check.join(',');
	if(id=='')alert('请选择需要转移的选项!');
	else if(model=='')alert('非法操作!');
	else if($("#"+obj).val()==''){
		alert('请选择转移的分类!');
		$("#"+obj).focus();
	}
	else{
		$('#SysMove').dialog('open');
		url = APP+"/do/move/id/"+id+"/model/"+model+"/cid/"+$("#"+obj).val();
	}
}

function status(obj,where,model,fields){
	
	if(where==''||model==''||fields==''||data==''){
		alert('非法操作!');
		return false;	
	}
	var data = $(obj).children().html();
	data = data==1 ? 2 : 1;
	var datas = "where="+where+"&model="+model+"&fields="+fields+"&data="+data;

	$.ajax({
	   type: "GET",	
	   url:  APP+"/do/status/",
	   data: datas,
	   success: function(data){
			var dataObj=eval("("+data+")");//转换为json对象
			if(dataObj['data']==0){
				alert('操作失败!');	
			}else{
				if(dataObj['data']=="1"){
					$(obj).children().addClass('ui-icon-check');
					$(obj).children().removeClass('ui-icon-help');
					$(obj).children().removeClass('ui-icon-closethick');
				}else{
					$(obj).children().removeClass('ui-icon-check');
					$(obj).children().removeClass('ui-icon-help');
					$(obj).children().addClass('ui-icon-closethick');
				}
				$(obj).children().html(dataObj['data']);
			}
	   },
	   error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert('操作失败!通信问题!');
	   }
	});
	
}

function help(obj){
	$("#"+obj).dialog('open');
}

$(document).ready(function() {
	
	/* 定义SysDel框架样式 */
	$('#SysDel').dialog({
		autoOpen: false,
		width: 300,
		buttons: {
			"Ok": function() { 
				window.location.href=url;
			}, 
			"Cancel": function(){
				$(this).dialog("close"); 
			} 
		}
	});
	
	/* 定义SysDel框架样式 */
	$('#SysMove').dialog({
		autoOpen: false,
		width: 300,
		buttons: {
			"Ok": function() { 
				window.location.href=url;
			}, 
			"Cancel": function(){
				$(this).dialog("close"); 
			} 
		}
	});
	
	/* 定义SysDel框架样式 */
	$('#SysDone').dialog({
		autoOpen: false,
		width: 300,
		buttons: {
			"Ok": function() { 
				window.location.href=url;
			}, 
			"Cancel": function(){
				$(this).dialog("close"); 
			} 
		}
	});
	
});